<template>
<Modal
	v-model="show"
	title="批量导入"
	@on-ok="import_ok"
	>
	<div>
		 <Form :label-width="80">
			<!--FormItem label="选择公司">
				<Select v-model="company_id" style="width:200px">
					<Option v-for="item in companyList" :value="item.id" :key="item.id">{{ item.name }}</Option>
				</Select>
			</FormItem-->
			<FormItem label="上传文件">
				<Upload
					multiple
					type="drag"
					:action="upload_url"
					:on-success="handleSuccess"
					:format="['xlsx','xls']"
					accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
					:max-size="20480"
					:on-format-error="handleFormatError"
					:on-exceeded-size="handleMaxSize"
					>
					<div style="padding: 20px 0">
						<Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
						<p>点击或者拖动上传文件</p>
					</div>
				</Upload>
			</FormItem>
		</Form>
		<div slot="footer" style="text-align: center;">
			<Button type="success" style="width:100px;"  @click="download">下载模板</Button>
		</div>
		
	</div>
</Modal>
</template>

<script>


export default {
  name: 'upload_box',
  data(){
	return {
		show:false,
		mark:'',
		company_id:0,
		companyList:[],
		upload_url:Whttp.upload_url,
		type:0
	};
  },
  props:['value','cinfo'],
  created(){
	this.show = this.value;
  },
  watch:{
	value(val){
		this.show = val;
	},
	show(val){
		this.$emit('input',val);
	}
  },
  methods: {
	import_ok(){
		var self = this;
		var postdata = {
			mark:this.mark,
			type:this.type,
			date_month:localStorage.cash_balance?localStorage.cash_balance:new Date().Format('yyyy-MM')
		};
		Whttp.load('Accounting/Cash/import_data',postdata,function(result){
			
			alert('导入成功');
			self.$emit('success',result);
		},function(result){
			alert(result.message);
		});
	},
	handleSuccess (res, file) {
			
		if(res.result_code==0){
			var ls_file = res.data[0];
			this.mark = ls_file.mark;
		}
		
	},
	handleFormatError (file) {
		this.$Notice.warning({
			title: 'The file format is incorrect',
			desc: 'File format of ' + file.name + ' is incorrect, please select jpg or png.'
		});
	},
	handleMaxSize (file) {
		this.$Notice.warning({
			title: 'Exceeding file size limit',
			desc: 'File  ' + file.name + ' is too large, no more than 2M.'
		});
	},
	download(){
		let url = Whttp.baseUrl + "upload.xlsx";
		window.open(url)
	}
  }
}
</script>
<style scoped>
.price{
	color: red;
    margin: 0 5px;
}
.defwid{
	width:220px;
}
</style>